import request, { PageQuery, PageResponse } from './request';

// 登录请求参数
export interface LoginRequest {
  username: string;
  password: string;
}

// 注册请求参数
export interface RegisterRequest {
  username: string;
  password: string;
  confirmPassword: string;
  realName: string;
  mobile: string;
  email: string;
}

// 注册响应数据
export interface RegisterResponse {
  message: string;
}

// 登录响应数据
export interface LoginResponse {
  token: string;
  tokenType: string;
}

// 用户信息
export interface UserInfo {
  id: number;
  username: string;
  realName: string;
  mobile: string;
  email: string;
  status: number;
  deptId: number;
  createTime: string;
  updateTime: string;
}

// 菜单信息
export interface MenuInfo {
  id: number;
  menuName: string;
  menuPath: string;
  menuIcon: string;
  parentId: number;
  sortOrder: number;
  status: number;
  children?: MenuInfo[];
}

// 认证API
export const authApi = {
  // 用户登录
  login: (data: LoginRequest): Promise<LoginResponse> => {
    return request.post('/auth/login', data);
  },

  // 用户注册
  register: (data: RegisterRequest): Promise<RegisterResponse> => {
    return request.post('/auth/register', data);
  },

  // 用户登出
  logout: (): Promise<void> => {
    return request.post('/auth/logout');
  },

  // 获取用户信息
  getUserInfo: (): Promise<UserInfo> => {
    return request.get('/auth/userinfo');
  },

  // 获取用户菜单
  getUserMenus: (): Promise<MenuInfo[]> => {
    return request.get('/auth/menus');
  },
};